package com.sky.controller.admin;

import com.sky.constant.ShopConstant;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

/**
 * @Author cp-月入过万
 * @Date 2025/5/16
 */
@RestController
@RequestMapping("/admin/shop")
@Slf4j
@Api(tags = "店铺相关接口")
public class ShopController {
    @Autowired
    private RedisTemplate  redisTemplate;
    /**
     * 设置店铺营业状态
     * @param status
     * @return
     */
    @PutMapping("/{status}")
    @ApiOperation("设置店铺营业状态")
    public Result setStatus(@PathVariable Integer status) {
        log.info("设置店铺营业状态：{}",status);
        redisTemplate.opsForValue().set(ShopConstant.SHOP_STATUS, Objects.equals(status, ShopConstant.SHOP_ENABLE) ?ShopConstant.SHOP_STATUS_OPEN:ShopConstant.SHOP_STATUS_CLOSE);
        return Result.success();
    }
    /**
     * 获取店铺的营业状态
     * @return
     */
    @GetMapping("/status")
    @ApiOperation("获取店铺的营业状态")
    public Result<Integer> getStatus() {
        String status = (String) redisTemplate.opsForValue().get(ShopConstant.SHOP_STATUS);
        log.info("获取店铺的营业状态：{}", Objects.equals(status, ShopConstant.SHOP_STATUS_OPEN) ? "营业中" : "打烊中");
        return Objects.equals(status, ShopConstant.SHOP_STATUS_OPEN)?Result.success(ShopConstant.SHOP_ENABLE):Result.success(ShopConstant.SHOP_DISABLE);
    }
}
